//
//  ProductViewController.m
//  123Mua_Modules
//
//  Created by duong nguyen on 11/3/12.
//  Copyright (c) 2012 uit. All rights reserved.
//

#import "ProductViewController.h"

@interface ProductViewController ()

@end

@implementation ProductViewController
@synthesize startPoint;
- (id)initWithStyle:(UITableViewStyle)style
{
    self = [super initWithStyle:style];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    [self.tableView setRowHeight:414];
    //[self.view setBackgroundColor:[UIColor colorWithRed:(196.f/255.f) green:(205.f/225.f) blue:(224.f/225.f) alpha:1.0]];
    
    [self.tableView setBackgroundColor:[UIColor colorWithPatternImage:[UIImage imageNamed:@"table_background.png"]]];
    [self.tableView setBackgroundView:nil];	
    UISwipeGestureRecognizer *gesture=[[UISwipeGestureRecognizer alloc]initWithTarget:self action:@selector(handleTouches)];
    gesture.delegate=self;
    [self.tableView addGestureRecognizer:gesture];
    
    [gesture release];
}

-(void)handleTouches{
    NSLog(@"Touch");
}
- (void)viewDidUnload
{
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
#warning Potentially incomplete method implementation.
    // Return the number of sections.
    return 3;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
#warning Incomplete method implementation.
    // Return the number of rows in the section.
    return 1;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"Cell";
    ProductCell *cell = [[[ProductCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier]autorelease];
    
    // Configure the cell...
    [cell.productLabel setText:@"xxx"];
    cell.backgroundView=[[[UIView alloc]initWithFrame:CGRectZero]autorelease];
    [cell.backgroundView setNeedsDisplay];
    
    return cell;
}

/*
// Override to support conditional editing of the table view.
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath
{
    // Return NO if you do not want the specified item to be editable.
    return YES;
}
*/

/*
// Override to support editing the table view.
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (editingStyle == UITableViewCellEditingStyleDelete) {
        // Delete the row from the data source
        [tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
    }   
    else if (editingStyle == UITableViewCellEditingStyleInsert) {
        // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
    }   
}
*/

/*
// Override to support rearranging the table view.
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath
{
}
*/

/*
// Override to support conditional rearranging of the table view.
- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath
{
    // Return NO if you do not want the item to be re-orderable.
    return YES;
}
*/

#pragma mark - Table view delegate

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    
}

#pragma mark - ScrollView Delegate
-(void)scrollViewWillBeginDecelerating:(UIScrollView *)scrollView{
    startPoint=scrollView.contentOffset;
}

-(void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView{
    CGPoint endPoint=scrollView.contentOffset;
    float distance=startPoint.y-endPoint.y;
    if (distance>50) {
        [UIView animateWithDuration:0.5 delay:0.0 
                            options:UIViewAnimationOptionCurveEaseInOut 
                         animations:^{
                             self.tabBarController.tabBar.center=CGPointMake(160, 455);
                         } completion:nil];
        //NSLog(@"Keo len");
    }else {
        if (distance<-50) {
            [UIView animateWithDuration:0.5 delay:0.0 
                                options:UIViewAnimationOptionCurveEaseInOut 
                             animations:^{
                                 self.tabBarController.tabBar.hidden=NO;
                                 self.tabBarController.tabBar.center=CGPointMake(160, 505);
                             } completion:nil];
        }
    }
}
@end
